/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/*  description :JS 访问Android原生功能插件
 *  author :hetanhong
 *  create :2014-6-17
 *  update : 2014-8-28

 */
(function (cordova) {
    var define = cordova.define;

    define("cordova/plugin/getIntent", function (require, exports, module) {

        var argscheck = require('cordova/argscheck'),
            exec = require('cordova/exec');
        // 获取当前activity intent 参数
        exports.getIntent = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.getIntent', arguments);
            exec(successCB, failCB, "getIntent", "getIntent", message);

        };
        // 设置当前activity intent 参数
        exports.setIntent = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.setIntent', arguments);
            exec(successCB, failCB, "getIntent", "setIntent", message);

        };
        // 获取应用版本号
        exports.getVersion = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.getVersion', arguments);
            exec(successCB, failCB, "getIntent", "getVersion", message);

        };
        // 安装应用
        exports.install = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.install', arguments);
            exec(successCB, failCB, "getIntent", "install", message);

        };
        // 打开新的activity
        exports.openView = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.openView', arguments);
            exec(successCB, failCB, "getIntent", "openView", message);

        };
        // 打开新的activity
        exports.openViewB = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.openViewB', arguments);
            exec(successCB, failCB, "getIntent", "openViewB", message);

        };
        // 打开新的activity
        exports.openViewC = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.openViewC', arguments);
            exec(successCB, failCB, "getIntent", "openViewC", message);

        };
        // 打开新的activity
        exports.openViewG = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.openViewG', arguments);
            exec(successCB, failCB, "getIntent", "openViewG", message);

        };
        // 关闭当前activity
        exports.closeView = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.closeView', arguments);
            exec(successCB, failCB, "getIntent", "closeView", message);

        };
        // 退出当前应用
        exports.exit = function (message, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.exit', arguments);
            exec(successCB, failCB, "getIntent", "exit", message);

        };
        // 页面添加遮罩
        exports.show = function (message, successCB, failCB) {

            //  argscheck.checkArgs('AFF', 'Notification.activityStart', arguments);
            return;
            exec(null, null, 'Notification', 'activityStart', [  "OA系统", message[1] ]);
            //  exec(successCB, failCB, "getIntent", "show", message);

            if (message.length <= 2) {
                setTimeout(function () {
                    exec(null, null, 'Notification', 'activityStop', []);
                }, 2000)
            }

        };
        // 页面隐藏遮罩
        exports.hide = function (msg, successCB, failCB) {
            return;
            argscheck.checkArgs('AFF', 'notification.activityStop', arguments);
            navigator.notification.activityStop();
            //  exec(null, null, 'Notification', 'activityStop', []);
        };
        //退回登录界面
        exports.startTop = function (msg, successCB, failCB) {
            argscheck.checkArgs('AFF', 'getIntent.startTop', arguments);
            exec(null, null, 'getIntent', 'startTop', []);
        };
    });

    cordova.addConstructor(function () {
        if (!window.plugins) {
            window.plugins = {};
        }
        console.log("将插件注入cordova...");
        window.plugins.getIntent = cordova.require("cordova/plugin/getIntent");
        console.log("注入结果：" + typeof (window.plugins.getIntent));
    });
})(cordova);